package com.jlcloud.core.sms.config;

import com.github.qcloudsms.SmsMultiSender;
import lombok.AllArgsConstructor;
import com.jlcloud.core.redis.cache.JlCloudRedis;
import com.jlcloud.core.sms.TencentSmsTemplate;
import com.jlcloud.core.sms.props.SmsProperties;
import com.jlcloud.core.tool.utils.Func;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 腾讯云短信配置类
 *
 * @author By: JlCloud <br>
 * @Package: com.jlcloud <br>
 * @CreateTime: 2024-12-03 21:45 <br>
 * @Copyright: 2021 www.jilianjituan.com Inc. All rights reserved. <br>
 * @Caution 注意：本内容仅限于冀联人力集团内部传阅，禁止外泄以及用于其他的商业目的 <br>
 */
@AutoConfiguration
@AllArgsConstructor
@ConditionalOnClass(SmsMultiSender.class)
@EnableConfigurationProperties(SmsProperties.class)
@ConditionalOnProperty(value = "sms.name", havingValue = "tencent")
public class TencentSmsConfiguration {

	private final JlCloudRedis jlcloudRedis;

	@Bean
	public TencentSmsTemplate tencentSmsTemplate(SmsProperties smsProperties) {
		SmsMultiSender smsSender = new SmsMultiSender(Func.toInt(smsProperties.getAccessKey()), smsProperties.getSecretKey());
		return new TencentSmsTemplate(smsProperties, smsSender, jlcloudRedis);
	}

}
